package com.foreknow.demo02;

import java.util.Scanner;
//contrl+aut+l 格式化
/**
 * 登录注册功能的实现
 */
public class HomeWork4 {
    public static void main(String[] args) {
        boolean register = false;//注册的标识位
        boolean isLogin = false;//登录的标识位
        String answer = "y";

        String userName = "";//初始化变量
        String password = "";//初始化变量
        Scanner input = new Scanner(System.in);

        do {
            System.out.println("**************************");
            System.out.println("1.  注册");
            System.out.println("2.  登录");
            System.out.println("3.  抽奖");
            System.out.println("**************************");

            System.out.println("请选择菜单:");
            int choice = input.nextInt();
            switch (choice){
                case 1:
                    System.out.println("注册");
                    System.out.println("用户名:");
                    userName = input.next();
                    System.out.println("密码:");
                    password = input.next();
                    //生成一个四位的随机数
                    int cardNumber =(int)(Math.random()*(9999-1000))+1000;
                    System.out.println(userName+"------"+password+"------"+cardNumber);
                    //将注册的标识位改为true
                    register = true;
                    break;
                case 2:
                    if(register) {
                        for(int i = 1;i<=3;i++){
                            System.out.println("请输入登录的用户名:");
                            String inputName = input.next();
                            System.out.println("请输入登录的密码:");
                            String inputPassword = input.next();
                            //判断登录的信息与注册时候的信息相同,字符串之间比较等价一定要使用equals
                            if(inputName.equals(userName)&&inputPassword.equals(password)){
                                System.out.println("welcome:"+userName);
                                isLogin = true;
                                break;
                            }else if(i<3){
                                System.out.println("您输入的用户名和密码不正确，还有"+(3-i)+"次机会");
                            }else {
                                System.out.println("3次错误的用户信息！！！！！！");
                            }
                        }
                    }else {
                        System.out.println("请先注册，然后才能登录");
                    }

                    break;
                case 3:
                    System.out.println("抽奖");

                    break;
            }
            System.out.println("是否继续(y/n)");
            answer = input.next();
        }while(answer.equals("y"));

        if(answer.equals("n")){
            System.out.println("系统退出了，谢放使用......");
        }

    }
}